<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <style>
        .table {
            width: 800px;
            max-width: 800px;
            margin: auto;
        }

        h1 {
            text-align: center;
            margin: 30px 0px;
        }

        img {
            width: 80px;
            height: 80px;
        }
    </style>
</head>

<body>
    <h1>商品信息</h1>
    <table width="600" class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>商品名</th>
                <th>图片信息</th>
                <th>单价</th>
                <th>库存</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

</body>

</html>
<script src="https://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.2.min.js"></script>
<script>


    // 发送ajax请求
    $.ajax({
        type: "get",
        url: "http://localhost:3000/goodslist",
        success(data) {
            console.log(data);
            render(data) 
        },error(err){
            
        }
    })



    function render(data) {
        let str = ""

        data.results.forEach(ele => {

            str += `<tr>
                <td>${ele.tradeName}</td>
                <td><img src='${ele.picture}' /></td>
                <td>${ele.price}</td>
                <td>${ele.stock}</td>
          </tr> `

        });

        $("tbody").html(str)
    }




</script>